
INCLUDEPATH = -I../../include/board/isamips_qemu/ -I../../include/processor/isamips_qemu
CMDPREFIX = mips-sde-elf-
ENDIAN = -EL
SMALLDATALIMIT = -G 0
CPLOPTIONS := -mips32r2 $(ENDIAN) $(SMALLDATALIMIT)
DEBUGMODE = -g -D __D_OEOS_DEBUG__

export GCC := $(CMDPREFIX)gcc $(CPLOPTIONS) $(DEBUGMODE) -fno-zero-initialized-in-bss -Werror
export LD := $(CMDPREFIX)ld $(ENDIAN) $(SMALLDATALIMIT)
export OBJCOPY := $(CMDPREFIX)objcopy
export AS := $(CMDPREFIX)as $(CPLOPTIONS)
export STRIP := $(CMDPREFIX)strip

all: image.elf
	$(OBJCOPY) --only-keep-debug image.elf image.sym
	$(STRIP) -o image_strip.elf image.elf
	$(OBJCOPY) -O binary image_strip.elf image.bin

image.elf: board.o test.o processor.o
	$(LD) -r test.o board.o processor.o -o image.o
	$(LD) --script=./ldscript -o image.elf image.o

test.o: test_entry.o test_mm.o
	$(LD) -r test_entry.o test_mm.o -o test.o

test_mm.o: test_mm.c
	$(GCC) -c -I. $(INCLUDEPATH) -o test_mm.o test_mm.c

test_entry.o: test_entry.c
	$(GCC) -c -I. $(INCLUDEPATH) -o test_entry.o test_entry.c

board.o:
	make -C ../board/isamips_qemu all
	cp ../board/isamips_qemu/board.o .

processor.o:
	make -C ../processor/isamips_qemu all
	cp ../processor/isamips_qemu/processor.o .

clean:
	-rm -rf ./*.o
	-rm -rf ./*~
	-rm -rf ./*.elf
	-rm -rf ./*.bin
	-rm -rf ./*.sym
	-make -C ../board/isamips_qemu clean
	-make -C ../processor/isamips_qemu clean

